home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / applic / ntp / acts.arc / CMPLST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-14  |  2.7 KB  |  71 lines

  1. int cmplst(buf,count,osec,obuf)
  2. char buf[];
  3. int *count;
  4. int *osec;
  5. char obuf[];
  6. {
  7. /*
  8.         this subroutine compares the current received date,time and dst
  9.         flag as part of the line received in buf
  10.         with the previously received values in the array obuf and osec
  11.         which hold the old time string and seconds, respectively.
  12.         the current values are then copied into array obuf to get ready
  13.         for the next comparison.
  14.  
  15.         if the two lines are consecutive (dates equal and seconds differ
  16.         by one) then cmplst returns 1. if this is the first comparison
  17.         then cmplst copies the line into the buffer and returns 0. if the
  18.         value of the second is < 58 then count is
  19.         incremented so that a comparison will be made on the next call.
  20.         if the second is >= 58 count is left alone since the next second
  21.         may wrap to the next minute making comparisons
  22.         very difficult. if the comparison fails, cmplst returns -1.
  23. */
  24. #include <stdio.h>
  25. char nbuf[25];       /* current time string*/
  26. int nsec;            /* current seconds value*/
  27. int  j,k,l;          /* used for loop control */
  28. int err;             /* used to hold detected error */
  29. /*
  30.         if first time through just do copy of old to new.
  31.         extract current seconds and store in osec
  32.         if current sec is 58, 59 or 60 leave count at zero so
  33.         that next entry will be treated as first one to prevent a
  34.         comparison across a possible wrap
  35.         -> set seconds field to spaces to prevent comparison error
  36.         on change in seconds value
  37. */
  38.         if(*count == 0)
  39.            {
  40.            for(j=0; (buf[j] != 0) && (buf[j] != '-'); j++) ; /*find - */
  41.            l=0;
  42.            for(k=j-2; k<j+18; k++) obuf[l++]=buf[k];
  43.            *osec=10*(obuf[15] - '0') + (obuf[16] - '0');
  44.            obuf[15]=obuf[16]=' ';
  45.            if(*osec < 58) (*count)++;
  46.            return(0);
  47.            }
  48. /*
  49.         store corresponding segment of current line in nbuf, compute
  50.         current second and compare both
  51. */
  52.         for(j=0; (buf[j] != 0) && (buf[j] != '-'); j++)  ;
  53.         l=0;
  54.         for(k=j-2; k<j+18; k++) nbuf[l++]=buf[k];
  55.         nsec=10*(nbuf[15] - '0') + (nbuf[16] - '0');
  56.         (*osec)++;                /*advance previous to next second*/
  57.         nbuf[15]=nbuf[16]=' ';
  58.         err=1;
  59.         for(k=0; k<20; k++) if(nbuf[k] != obuf[k]) err= -1;
  60.         if(nsec != *osec) err= -1;
  61.         if(err == -1)
  62.         {
  63.         nbuf[20]=obuf[20]='\0';
  64.         printf("\n sequence error");
  65.         printf("\n first line=%s, sec=%d",obuf,*osec);
  66.         printf("\nsecond line=%s, sec=%d",nbuf, nsec);
  67.         *count=0;
  68.         }
  69.         return(err);
  70. }
  71.